from selenium import webdriver
from time import sleep

from selenium.webdriver.common.by import By

#多元素定位
driver= webdriver.Firefox()
driver.get("http://baidu.com")
ele = driver.find_element(By.LINK_TEXT,"新闻") #By.LINK_TEXT：定位的是 <a>标签的可见文本
ele.click()
#句柄：获取当前句柄
handle1=driver.current_window_handle
ele=driver.find_element(By.LINK_TEXT,"贴吧")
ele.click()
ele=driver.find_element(By.LINK_TEXT,"文库")
ele.click()
#滚动条用法
# driver.execute_script("window.scrollTo(0,500)")
# sleep(2)
# driver.execute_script("window.scrollTo(0,1500)")
# sleep(2)

#所有句柄
handles = driver.window_handles
for h in handles:
    if h != handle1:
        driver.switch_to.window(h)
        sleep(2)
        # print(driver.title)
        if driver.title=="百度新闻——海量中文资讯平台":
            driver.find_element(By.PARTIAL_LINK_TEXT,"哪吒").click()#By.PARTIAL_LINK_TEXT 部分匹配
            sleep(5)
sleep(2)
driver.quit()